package sonoCommunity.service;

import org.jasypt.util.password.BasicPasswordEncryptor;
import org.jasypt.util.password.PasswordEncryptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import sonoCommunity.dao.UserDao;

@Service
public class UserService {

	  @Autowired UserDao userDao;
	  
	  
	  public boolean validLogin(PasswordEncryptor passwordEncryptor,String userMail){
		 if (userDao.getUserPassword(userMail)==null){ 
			 return false;
		 }else{
			 return true;
		 }
	  }
	  
	  public boolean validPassword(PasswordEncryptor passwordEncryptor,String userMail, String password){
		  
		  String encryptedPassword = userDao.getUserPassword(userMail);
		  if(passwordEncryptor.checkPassword(password, encryptedPassword)) {
			  //password Valid
			  return true;
		  }else{
			  //password no valid
			  return false;
		  }
	  }
	  
}
